﻿(function () {
    $(function () {

        var _$table = $('#tb');
        var _atlasService = abp.services.app.atlas;

        //  var _permissions = {
        //      create: abp.auth.hasPermission("Pages.Atlas.CreateAtlas"),
        //      edit: abp.auth.hasPermission("Pages.Atlas.EditAtlas"),
        //      'delete': abp.auth.hasPermission("Pages.Atlas.DeleteAtlas")

        //  };


        //var _createOrEditModal = new app.ModalManager({
        //      viewUrl: abp.appPath + 'Mpa/AtlasManage/CreateOrEditAtlasModal',
        //      scriptUrl: abp.appPath + 'Areas/Mpa/Views/AtlasManage/_CreateOrEditAtlasModal.es5.min.js',
        //      modalClass: 'CreateOrEditAtlasModal'
        //  });
        //alert('111');
        var myChart1 = echarts.init(document.getElementById('main1'));
        var myChart2 = echarts.init(document.getElementById('main2'));
        var option1 = {
            title: {
                text: '折线图堆叠'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['AVERAGE(X)', 'CLX', 'UCLX', 'LCLX']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25'],
                max: '25'
            },
            yAxis: {
                type: 'value'
                //min: 4.9,
                //max: 5.2,
                //interval: 0.07
            },
            series: []

        };
        var option2 = {
            title: {
                text: '折线图'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['MAX-MIN(R)', 'CLR', 'UCLR', 'LCLR']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25'],
                max: '25'
            },
            yAxis: [{
                type: 'value'
                //min: 0,
                //max: 0.3,
                //interval:0.1
            }],
            series:
            [
            ]
        };
        myChart1.setOption(option1);
        myChart2.setOption(option2);
        echarts.connect([myChart1, myChart2]);









        $("#btn-query").click(function () {

            layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
            var _line = document.getElementById("lineId").value;
            var _seatType = document.getElementById("seatTypeId").value;
            var _stationNo = document.getElementById("stationNoId").value;
            var _date = document.getElementById("time1").value;

            document.getElementById("line").innerText = _line;
            document.getElementById("seatType").innerText = _seatType;
            document.getElementById("stationNo").innerText = _stationNo;
            document.getElementById("date").innerText = _date;

            //_atlasService.tb_DataSource({});
            $.post("/AtlasCpks/tb_DataSource", {
                LineId: _line,
                StationNoId: _stationNo,
                SeatTypeId: _seatType,
                Time1: document.getElementById("time1").value,
                Time2: document.getElementById("time2").value
            },
                function (result) {

                    //$("#div_Content").html(result);
                    //innerHTML  html 要大写 
                    document.getElementById("div_Content").innerHTML = result.lststr[0];
                    document.getElementById("explain2").innerHTML = result.lststr[1];
                    document.getElementById("chart1up").innerHTML = result.lststr[2];
                    document.getElementById("chart2up").innerHTML = result.lststr[3];
                    option1.series = result.series[0];
                    //option1.legend.data = result[1].legend;
                    //option1.grid = result[1].grid;
                    myChart1.hideLoading();
                    myChart1.setOption(option1);

                    option2.series = result.series[1];
                    //option1.legend.data = result[1].legend;
                    //option1.grid = result[1].grid;
                    myChart2.hideLoading();
                    myChart2.setOption(option2);
                    layer.closeAll('loading');
                });
            
        });

        //导出为excel文档
        $('#btn-export').click(function () {
            var _line = document.getElementById("lineId").value;
            var _seatType = document.getElementById("seatTypeId").value;
            var _stationNo = document.getElementById("stationNoId").value;
            var _date = document.getElementById("time1").value;

            layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
            window.location.href = '/AtlasCpks/Export' + '?LineId=' + _line + '&StationNoId=' + _stationNo
                + '&SeatTypeId=' + _seatType + '&Time1=' + document.getElementById("time1").value
                + '&Time2=' + document.getElementById("time2").value;
            layer.closeAll('loading');


            //$.get("/AtlasCpks/Export", {
            //    LineId: _line,
            //    StationNoId: _stationNo,
            //    SeatTypeId: _seatType,
            //    Time1: document.getElementById("time1").value,
            //    Time2: document.getElementById("time2").value
            //},
            //    function (result) {
            //        //alert('111');
            //        ////$("#div_Content").html(result);
            //        ////innerHTML  html 要大写 
            //        //document.getElementById("div_Content").innerHTML = result.lststr[0];
            //        //document.getElementById("explain2").innerHTML = result.lststr[1];
            //        //document.getElementById("chart1up").innerHTML = result.lststr[2];
            //        //document.getElementById("chart2up").innerHTML = result.lststr[3];
            //        //option1.series = result.series[0];
            //        ////option1.legend.data = result[1].legend;
            //        ////option1.grid = result[1].grid;
            //        //myChart1.hideLoading();
            //        //myChart1.setOption(option1);

            //        //option2.series = result.series[1];
            //        ////option1.legend.data = result[1].legend;
            //        ////option1.grid = result[1].grid;
            //        //myChart2.hideLoading();
            //        //myChart2.setOption(option2);
            //    });
            ////layer.load(0, {
            ////    shade: [0.3, '#000'] //0.1透明度的白色背景
            ////});

            //$.post("/AtlasCpks/Export", {

            //},
            //    function (result) {
            //        alert('111');
            //    }
            //);

            ////_atlasService
            ////    .getTestImsToExcel({})
            ////    .done(function (result) {
            ////        layer.closeAll('loading');
            ////        app.downloadTempFile(result);
            ////    });
        });

        $("#time1").datetimepicker({
            minView: "month",//设置只显示到月份
            format: "yyyy-mm-dd",//日期格式
            //format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
        });
        $("#time2").datetimepicker({
            minView: "month",//设置只显示到月份
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
        });



    });
})();
